/*
 * Copyright 2010 Nicolas Lochet Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
 */
package org.nicocube.wol.admin.client;

import java.util.List;

import org.nicocube.wol.data.client.User;
import org.nicocube.wol.ui.client.MyFlexTable;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.RootPanel;

public class WolAdmin implements EntryPoint {

	private final WolAdminServiceAsync wolAdminService = GWT.create(WolAdminService.class);
	
	@Override
	public void onModuleLoad() {
		
		final DecoratorPanel dp = new DecoratorPanel();
		final MyFlexTable myFlexTable = new MyFlexTable();
		
		wolAdminService.getAllUser(new AsyncCallback<List<User>>() {
			@Override
			public void onSuccess(List<User> result) {
				
				myFlexTable.addRow(
						"id","login","password","creation","birthday","gender","country","language","news","promo","partner"
				);
				
				for (User user : result) {
					myFlexTable.addRow(
							user.getId(),
							user.getLogin(),
							user.getPassword(),
							user.getCreationDate(),
							user.getDateOfBirth(),
							user.getGender(),
							user.getCountry(),
							user.getLanguage(),
							user.isAcceptNewsLetter(),
							user.isAcceptPromotion(),
							user.isAcceptPartner()
					);
				}
				
				dp.add(myFlexTable);
			}
			
			@Override
			public void onFailure(Throwable caught) {
				
			}
		});
		
		RootPanel.get().add(dp);

	}

}
